package cn.itcast.com.day08;

public class demo1 {

    public static void main(String[] args) {
        Duck duck = new Duck();
        dog dog = new dog();
        collectAnimalStudy(duck);
        collectAnimalStudy(dog);

    }


    //利用多态来实现收集不同动物的声音并研究的功能
    public static void collectAnimalStudy(Animal animal){
        if(animal instanceof Duck){
            Duck duck = (Duck) animal;
            duck.swim();
        }
        animal.shout();
    }

}
class Animal{
    String name = "xxxAnimal";

    public void eat(){
        System.out.println("Animal eating");
    }

    public void shout(){
        System.out.println("Animal shout");
    }
}

class cat extends Animal{
    String name = "xxxcat";

    @Override
    public void eat(){
        System.out.println("🐱吃🐟");
    }

    @Override
    public void shout(){
        System.out.println("喵喵喵");
    }
}

class dog extends Animal{
    String name = "xxxdog";

    @Override
    public void eat(){
        System.out.println("🐕吃💀");
    }

    @Override
    public void shout(){
        System.out.println("汪汪汪");
    }
}

class Duck extends Animal{
    public void eat(){
        System.out.println("鸭子吃鱼");
    }
    public void shout(){
        System.out.println("g呱呱呱");
    }
    public void swim(){
        System.out.println("鸭子游泳");
    }
}

